package com.github.wj.web.controller;

import com.github.wj.web.entity.Gxxs0101Bm;
import com.github.wj.web.entity.TSjzxDmjzx;
import com.github.wj.web.entity.TjxZyGxjx01;
import com.github.wj.web.service.CustomDmjzxService;
import com.github.wj.web.service.CustomZyService;
import com.github.wj.web.service.StudentRegisterService;
import com.jsoniter.output.JsonStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Create by IntelliJ IDEA
 * 用户：王建
 * 日期：2018/3/13
 */
@Controller
@RequestMapping("/s/wx/register")
public class StudentRegisterController {

    @Autowired
    private StudentRegisterService service;

    @Autowired
    private CustomDmjzxService dmjzxService;

    @Autowired
    private CustomZyService zyService;

    @RequestMapping("/index")
    public String index(HttpServletRequest request, ModelMap modelMap){
        service.registerIndex(modelMap);
        return "mobile/index";
    }

    /**
     * 获取专业信息
     * @param orgId
     * @return
     */
    @RequestMapping("/{orgId}/zy")
    @ResponseBody
    public String getZy(@PathVariable Long orgId){
        List<TjxZyGxjx01> zyGxjx01List=zyService.getAllByOgrid(orgId);
        Map<String,Object> map=new HashMap<>();
        map.put("dataList",zyGxjx01List);
        return JsonStream.serialize(map);
    }

    /**
     * 获取市
     * @param dm
     * @return
     */
    @RequestMapping("/{dm}/city")
    @ResponseBody
    public String getCity(@PathVariable Long dm){
        List<TSjzxDmjzx> list=dmjzxService.getAllById(dm,2);
        Map<String,Object> map=new HashMap<>();
        map.put("dataList",list);
        return JsonStream.serialize(map);
    }

    /**
     * 区
     * @param dm
     * @return
     */
    @RequestMapping("/{dm}/section")
    @ResponseBody
    public String getSection(@PathVariable Long dm){
        List<TSjzxDmjzx> list=dmjzxService.getAllById(dm,4);
        Map<String,Object> map=new HashMap<>();
        map.put("dataList",list);
        return JsonStream.serialize(map);
    }

    /**
     * 专业
     * @param dm
     * @return
     */
    @RequestMapping("/{dm}/organization")
    @ResponseBody
    public String getOrganization(@PathVariable Long dm){
        List<TjxZyGxjx01> list=zyService.getAllByOgrid(dm);
        Map<String,Object> map=new HashMap<>();
        map.put("dataList",list);
        return JsonStream.serialize(map);
    }

    @PostMapping("/upload")
    @ResponseBody
    public String uploadFile(MultipartHttpServletRequest request){
        return service.uploadFile(request);
    }

    @PostMapping("/save")
    public String save(Gxxs0101Bm gxxs0101Bm,ModelMap modelMap){
        boolean info=service.save(modelMap,gxxs0101Bm);
        if(info){
            modelMap.put("title","保存成功！");
            modelMap.put("info",true);
        }else {
            modelMap.put("title","保存失败！");
            modelMap.put("info",false);
        }
        return "mobile/entity";
    }

}
